package com.wk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wk.dao.CmfzLogDao;
import com.wk.entity.CmfzGuru;
import com.wk.entity.CmfzLog;
import com.wk.entity.Result;
import com.wk.service.CmfzGuruService;
import com.wk.service.CmfzLogService;
import jdk.nashorn.internal.runtime.regexp.joni.WarnCallback;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class CmfzLogServiceImpl implements CmfzLogService {

    @Autowired
    private CmfzLogDao cmfzLogDao;

    @Override
    public Result findAll(Integer page, Integer limit, String name) {

        QueryWrapper<CmfzLog> wrapper = new QueryWrapper<>();
        Page<CmfzLog> page2 = new Page<CmfzLog>(page, limit);
       // wrapper.like("adminName",name);

        Page<CmfzLog> cmfzLogPage = cmfzLogDao.selectPage(page2, wrapper);
        long total = cmfzLogPage.getTotal();
        List<CmfzLog> records = cmfzLogPage.getRecords();
        return new Result(0,"",(int)total,records);
    }

    @Override
    public Result delete(Integer id) {
        Result result = new Result();
        try {
            cmfzLogDao.deleteById(id);
            result.setData("删除成功");
        }catch (Exception e){
            e.printStackTrace();
            result.setData("删除失败");
            return result;
        }
        return result;
    }

}
